package com.shg.web.action.bbs;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.shg.bean.Book;
import com.shg.bean.bbs.FavoriteItem;
import com.shg.service.bbs.FavoriteService;
import com.shg.web.tools.WebTool;

@Controller
public class FavoriteAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//店铺的ID
	private String shopId;
	//
	private String message;
	//
	private FavoriteItem favoriteItem;
	//
	private List<Book> books;
	
	@Resource FavoriteService favoriteService;

	/**
	 * 收藏书籍
	 * @return
	 */
	public String stowBook(){
		if(WebTool.getLogin()!=null){
			try {
				favoriteService.insertBook(WebTool.getLogin().getId(), favoriteItem);
			} catch (Exception e) {
				e.printStackTrace();
				this.message="收藏书籍出现了异常";
				return ERROR;
			}	
		}else{
			return LOGIN;
		}
		return bookList();
	}
	/**
	 * 获取收藏的书籍
	 * @return
	 */
	public String bookList(){
		try {
			books = favoriteService.getBook(WebTool.getLogin().getId());
		} catch (Exception e) {
			e.printStackTrace();
			this.message="查询收藏的书籍发生异常";
			return ERROR;
		}
		return "bookList";
	}
	public String getShopId() {
		return shopId;
	}
	public void setShopId(String shopId) {
		this.shopId = shopId;
	}
	public FavoriteItem getFavoriteItem() {
		return favoriteItem;
	}
	public void setFavoriteItem(FavoriteItem favoriteItem) {
		this.favoriteItem = favoriteItem;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public List<Book> getBooks() {
		return books;
	}
	public void setBooks(List<Book> books) {
		this.books = books;
	}
}
